package com.smasher.doc.operation;

import android.content.Context;
import android.content.res.Resources;

import com.smasher.core.other.WeakReferenceHandler;
import com.smasher.doc.R;

import java.io.File;
import java.util.HashMap;

public class WorkTaskWriteRaw implements Runnable {

    private final File docDir;
    private final Resources resources;
    private final WeakReferenceHandler handler;
    private final String target;
    private final HashMap<String, String> contentMap;

    private final OperationWriteHelper operationReadHelper = new OperationWriteHelper();

    public static final int MSG_END = 1001;

    public WorkTaskWriteRaw(
            Context context,
            WeakReferenceHandler handler,
            HashMap<String, String> contentMap,
            String target
    ) {
        this.docDir = context.getExternalFilesDir("Doc");
        this.resources = context.getResources();
        this.handler = handler;
        this.target = target;
        this.contentMap = contentMap;
    }

    @Override
    public void run() {
        operationReadHelper.fillDocFromRaw(resources, R.raw.template10181844, contentMap, docDir, target);
        handler.sendMessage(handler.obtainMessage(MSG_END));
    }
}
